static-delta: Don't run bspatch when output object already exists
authorJohn Hiesey <john@hiesey.com>
Wed, 7 Oct 2015 21:43:13 +0000 (14:43 -0700)
committerColin Walters <walters@verbum.org>
Sat, 10 Oct 2015 14:31:10 +0000 (10:31 -0400)
There is already a check that the destination object does not
exist in all other cases when processing an incoming static delta.
However, the bspatch case would still try to run and fail. Add
an analogous check to that case as well.

https://bugzilla.gnome.org/show_bug.cgi?id=756260

src/libostree/ostree-repo-static-delta-processing.c

index 18687f8a3543a5ec19f80ebcdbb85d2ff6ac686a..f60ec7a1b8b6ff9e5e91d5b0d56c8b1928007ae5 100644 (file)
@@ -530,32 +530,35 @@ dispatch_bspatch (OstreeRepo                 *repo,
   if (!read_varuint64 (state, &length, error))
     goto out;
 
-  input_mfile = g_mapped_file_new_from_fd (state->read_source_fd, FALSE, error);
-  if (!input_mfile)
-    goto out;
+  if (!state->have_obj)
+    {
+      input_mfile = g_mapped_file_new_from_fd (state->read_source_fd, FALSE, error);
+      if (!input_mfile)
+        goto out;
 
-  buf = g_malloc0 (state->content_size);
-
-  opaque.state = state;
-  opaque.offset = offset;
-  opaque.length = length;
-  stream.read = bspatch_read;
-  stream.opaque = &opaque;
-  if (bspatch ((const guint8*)g_mapped_file_get_contents (input_mfile),
-               g_mapped_file_get_length (input_mfile),
-               buf,
-               state->content_size,
-               &stream) < 0)
-    goto out;
+      buf = g_malloc0 (state->content_size);
+
+      opaque.state = state;
+      opaque.offset = offset;
+      opaque.length = length;
+      stream.read = bspatch_read;
+      stream.opaque = &opaque;
+      if (bspatch ((const guint8*)g_mapped_file_get_contents (input_mfile),
+                   g_mapped_file_get_length (input_mfile),
+                   buf,
+                   state->content_size,
+                   &stream) < 0)
+        goto out;
 
-  if (!g_output_stream_write_all (state->content_out,
-                                  buf,
-                                  state->content_size,
-                                  &bytes_written,
-                                  cancellable, error))
-    goto out;
+      if (!g_output_stream_write_all (state->content_out,
+                                      buf,
+                                      state->content_size,
+                                      &bytes_written,
+                                      cancellable, error))
+        goto out;
 
-  g_assert (bytes_written == state->content_size);
+      g_assert (bytes_written == state->content_size);
+    }
 
   ret = TRUE;
  out: